#pragma once
#include "SkinWindowImpl.h"
#include "SkinFrame.h"

template <class T, class TBase  = CWindow , class TWinTraits = CControlWinTraits >
class CSkinFrameImpl : public CSkinWindowImpl<T, TBase, TWinTraits>, public CSkinFrame
{
public:
    CSkinFrameImpl()
    {
    }

    virtual ~CSkinFrameImpl()
    {
    }
public:
    SKIN_DECLARE_CLASS_NAME( _T( "SkinFrameImpl" ) )
public:
    BEGIN_MSG_MAP_EX( CSkinFrameImpl )
    MSG_WM_CLOSE( OnClose )
    MSG_WM_SIZE( OnSize )
    MSG_WM_ERASEBKGND( OnEraseBkgnd )
    MSG_WM_NCCALCSIZE( OnNcCalcSize )
    MSG_WM_PAINT( OnPaint )
    MSG_WM_WINDOWPOSCHANGED( OnWindowPosChanged )
    END_MSG_MAP()
public:

    void OnWindowPosChanged( LPWINDOWPOS lpWndPos )
    {
        CSkinFrame::OnWindowPosChanged( lpWndPos );
    }

    void OnPaint( HDC hDC )
    {
        CSkinFrame::OnPaint( hDC );
    }

    LRESULT OnNcCalcSize( BOOL bCalcValidRects, LPARAM lParam )
    {
        CSkinFrame::OnNcCalcSize( bCalcValidRects, lParam );
        return 0;
    }

    BOOL LoadXml( LPCTSTR lpszXml )
    {
        return CSkinFrame::LoadXml( lpszXml );
    }

    HWND Create(
        _In_opt_ HWND hWndParent = NULL,
        _In_ _U_RECT rect = NULL,
        _In_opt_z_ LPCTSTR szWindowName = NULL,
        _In_ DWORD dwStyle = 0,
        _In_ DWORD dwExStyle = 0,
        _In_ _U_MENUorID MenuOrID = 0U,
        _In_opt_ LPVOID lpCreateParam = NULL, LPCTSTR lpszClassName = NULL )
    {
        HWND hWnd = __super::Create( hWndParent, m_rcWindow, m_szWindowName, m_dwStyle, m_dwExStyle, MenuOrID, lpCreateParam, GetClassName() );
        CSkinFrame::Attach( hWnd );
        CenterWindow();
        return hWnd;
    }

    void OnSize( UINT nType, CSize size )
    {
        CSkinFrame::OnSize( nType, size );
    }

    BOOL OnEraseBkgnd( CDCHandle dc )
    {
        return CSkinFrame::OnEraseBkgnd( dc );
    }

    void OnClose()
    {
        SetMsgHandled( FALSE );
        ::PostQuitMessage( 0 );
    }
};